$(function(){
    function init(openId){

        var openId = localStorage.getItem("openId");
          var openId1 = getQueryString("openId");
          var id = getQueryString("id");
        console.log(openId)
        console.log(id)
        // $.ajax({
        //     type: "GET",
        //     url: baseUrl + "/rest/activeVipController/list/admin",
        //     contentType:"application/json;charset=UTF-8",
        //     data: {
        //         pageNumber:'1',
        //         pageSize:'100',
        //       },
        //     dataType: "json",
        //     success: function(data){
        //         console.log(data)
        //         if(data.ok){
        //             if(data.data.length){
        //                 for(let i =0;i<data.data.length;i++){
        //                     if(data.data[i].fxj02 ==)
        //                 }
        //             }
        //         }
        //     }
        // }),
        $.ajax({
            type: "GET",
            url: baseUrl + "/rest/activeJoinController/list/admin",
            contentType:"application/json;charset=UTF-8",
            data: {
                pageNumber:'1',
                pageSize:'100',
                id:id,
              },
            dataType: "json",
            success: function(data){
                console.log(data)
                if(data.ok){
                    if(data.data.length){
                        let a = '';
                        $("#carDetail").html(' ');
                        for(let i=0;i<1;i++){
                            console.log(data.data[i].fxjOut13)
                            console.log(baseUrl)
                            // a +='<div class="banner">';
                            // a += '<img src="'+baseUrl+"/" + data.data[i].fxjOut13+'" alt="">';
                            // a +='</div>';
                            a +='<div class="banner">';
                            a +='<img src="../static/images/active.png"  id="banner" alt="">';
                            a +='</div>';
                            a +='<div class="activeName">'+data.data[i].fxjOut02+'</div>';
                            a +='<div class="userName"><text>姓名：</text>'+data.data[i].fxjOut06+'</div>';
                            a +='<div class="userTel"><text>电话：</text>'+data.data[i].fxjOut07+'</div>';
                            a +='<div class="button">';
                            a +='<div class="yes" data-fxjOut01="'+data.data[i].fxjOut01+'" data-fxjOut02="'+data.data[i].fxjOut02+'" data-fxjOut04="'+data.data[i].fxjOut04+'" data-fxjOut06="'+data.data[i].fxjOut06+'" data-fxjOut07="'+data.data[i].fxjOut07+'"data-fxjOut13="'+data.data[i].fxjOut13+'"data-fxjOut15="'+data.data[i].fxjOut15+'"data-fxjOut16="'+data.data[i].fxjOut16+'">确认</div>';
                            a +='<div class="no">取消</div>';
                            a +='</div>';
                            a +='<div class="tips">*非工作人员请勿擅自扫码点击确认，如有损失自行负责</div>';
                                           
                        }
                        $(".detail").html(a);
                        // 立即使用
                        $(".yes").click(function(){
                            let fxjOut01 = $(this).attr('data-fxjOut01');
                            let fxjOut02 = $(this).attr('data-fxjOut02');
                            let fxjOut04 = $(this).attr('data-fxjOut04');
                            let fxjOut06 = $(this).attr('data-fxjOut06');
                            let fxjOut07 = $(this).attr('data-fxjOut07');
                            let fxjOut13 = $(this).attr('data-fxjOut13');
                            let fxjOut15 = $(this).attr('data-fxjOut15');
                            let fxjOut16 = $(this).attr('data-fxjOut16');
                            InfoData={
                                id:id,
                                fxjOut01:fxjOut01,
                                fxjOut02:fxjOut02,
                                fxjOut04:fxjOut04,
                                fxjOut06:fxjOut06,
                                fxjOut07:fxjOut07,
                                fxjOut11:'已使用',
                                fxjOut13:fxjOut13,
                                fxjOut14:openId,
                                fxjOut15:fxjOut15,
                                fxjOut16:fxjOut16
                            }
                            $.ajax({
                                type: "PUT",
                                url: baseUrl + "/rest/activeJoinController/hx/"+id,
                                contentType:"application/json;charset=UTF-8",
                                data: JSON.stringify(InfoData),
                                success: function(data){
                                    console.log(data)
                                    if(!data.ok){
                                        alert('核销成功')
                                    }else{
                                        alert("核销失败")
                                    }
                                }
                            })

                        });
                    }else{
                        $("#carDetail").html('暂无数据');
                    }
                }else{
                    alert(data.message);
                }
            }
        });
        
    }
    function tab(dataType,openId){
        $.ajax({
            type: "GET",
            url: baseUrl + "/rest/lkCarApplyController/list/"+openId+"?pageNumber=1&pageSize=100",
            contentType:"application/json;charset=UTF-8",
            data: {
                orderData: dataType,
            },
            dataType: "json",
            success: function(data){
                console.log(data)
                if(data.ok){
                    if(data.data.length){
                        let a = '';
                        $("#carDetail").html(' ');
                        for(let i=0;i<data.data.length;i++){
                            a += '<div class="item">';
                            a += '<div class="item-a">';
                            if(data.data[i].name){
                                a += '<div class="l">'+data.data[i].name+'</div>';
                            }else{
                                a += '<div class="l"></div>';
                            }
                            // a += '<div class="l">'+data.data[i].name+'</div>';
                            a += '<div class="r">'+data.data[i].orderData+'</div>';
                            a += '</div>';
                            a += '<div class="item-b">';
                            a += '<div class="l">';
                            a += '<img src="'+baseUrl+"/img/server/" + data.data[i].remake1+'" alt="">';
                            a += '</div>';
                            a += '<div class="r">';
                            a += '<p class="a">'+data.data[i].carName+'</p>';
                            a += '<p class="b">申请服务:'+data.data[i].carType+'</p>';
                            a += '<p class="c">首租金额:'+data.data[i].carMoney+'元</p>';
                            a += '<p class="d">期数:'+data.data[i].rentDate+'期</p>';
                            a += '<p class="e">月供:'+data.data[i].rentMoney+'元</p>';
                            a += '</div>';
                            a += '</div>';
                            a += '</div>';
                        }
                        $("#order").html(a);
                    }else{
                        $("#carDetail").html('暂无数据');
                    }
                }else{
                    alert(data.message);
                }
            }
        });
    }
    var openId = localStorage.getItem("openId");
    if(openId == null || openId == ''){
        messageBox("获取个人信息失败");
        setTimeout(function(){
            loginFail('1'); // 一键登录
        },200);
        return false;
    }
    init(openId);// 初始化加载数据
    // 切换加载数据
    $(".header-item").click(function(){
        $(this).addClass("active").siblings().removeClass("active");
        var dataType = $(this).attr("data-type");
        if(dataType == '0'){
            tab("未完成",openId);
        }
        if(dataType == '1'){
            tab("已完成",openId);
        }
        if(dataType == '2'){
            init(openId);
        }
    }); 

    
});

function getQrcode(url){
    // console.log(name)
    // console.log(id)
    // console.log(activeName)

    $(".qrcode-box").css("display","block");
    let _w = $("#qrcode").width();
    jQuery('#qrcode').qrcode({
        render: "canvas", //也可以替换为table
        width: _w,
        height: _w,
        text: url,
    });
}